home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / c_toolbx.arc / BT_LOW.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-03-30  |  1.3 KB  |  48 lines

  1. /*  bt_low.c - low level functions for BTREE module */
  2. #include   "stdio.h"
  3. #include   "btree.h"
  4. #include   "bt_macro.h"
  5.  
  6. extern    IX_DESC    *pci ;
  7. extern    BLOCK    spare_block ;
  8.  
  9. BLOCK    *neighbor(l,direction)        /* get block to right of curr. one */
  10.   int    l ;                /* level to fetch neighbor on */
  11.   int    direction ;            /* left or right neighbor */
  12.   {
  13.      RECPOS   rnext ;
  14.      int      off   ;
  15.      BLOCK    *pb   ;
  16.  
  17.      pb = & spare_block ;
  18.      l = l + 1 ;            /* look in higher level index */
  19.      retrieve_block(l,CB(l),pb,CURR) ;    /* get offset on next/prev. entry */
  20.      if( direction == RIGHTN )
  21.     off = next_entry(pb,CO(l)) ;    /* get offset of next entry */
  22.      else
  23.     off = prev_entry(pb,CO(l)) ;    /* get offset of previous entry */
  24.      if( off < 0 )            /* at end or beginning ? */
  25.     return(NULL) ;
  26.      rnext = ENT_ADR(pb,off)->rptr ;    /* neighbor's block number */
  27.                     /* read it into memory */
  28.      retrieve_block(l-1,rnext,pb,NOT_CURR) ;
  29.      return( pb ) ;            /* return it's address */
  30.   }
  31.  
  32.  
  33. int  copy_current(l,pe)         /* copy current index entry */
  34.   int    l ;                /* at this level */
  35.   ENTRY *pe ;                /* to this address */
  36.   {
  37.      BLOCK *pb ;
  38.  
  39.      pb = & spare_block ;
  40.      retrieve_block(l,CB(l),pb,CURR) ;    /*  get curr. block */
  41.                     /* copy current entry */
  42.      copy_entry(pe,ENT_ADR(pb,CO(l) ) ) ;
  43.      return( IX_OK ) ;
  44.   }
  45.  
  46.  
  47.  
  48.